package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexSearchVo;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.service.GenericResponseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

	@Autowired
	private SearchService searchService;
	@Autowired
	private GenericResponseService responseBuilder;

	//     /api/search/albumInfo/upperAlbum/{albumId}
	@GetMapping("/upperAlbum/{albumId}")
	public Result<Void> upperAlbum(@PathVariable Long albumId) {
		searchService.upperAlbum(albumId);
		return Result.ok();
	}

// 	/api/search/albumInfo/lowerAlbum/{albumId}

	@GetMapping("lowerAlbum/{albumId}")
	public Result<Void> lowerAlbum(@PathVariable Long albumId) {
		searchService.lowerAlbum(albumId);
		return Result.ok();
	}

	// 	/api/search/albumInfo
	@PostMapping
	public Result<AlbumSearchResponseVo> findAlbumList(@RequestBody AlbumIndexQuery albumIndexQuery) throws IOException {
		return Result.ok(searchService.findAlbumList(albumIndexQuery));
	}

	// 	AlbumInfoIndexSearchVo
// 	/api/search/albumInfo/channel/{category1Id}
	@GetMapping("/channel/{category1Id}")
	public Result<List<AlbumInfoIndexSearchVo>> channel(@PathVariable Long category1Id) {
		return Result.ok(searchService.channel(category1Id));
	}

	// 	/api/search/albumInfo/completeSuggest/{keyword}
	@GetMapping("/completeSuggest/{keyword}")
	public Result<List<String>> completeSuggest(@PathVariable String keyword) {
		return Result.ok(searchService.completeSuggest(keyword));
	}

	@GetMapping("/updateLatelyAlbumRanking")
	public Result<Void> updateLatelyAlbumRanking() {
		searchService.updateLatelyAlbumRanking();
		return Result.ok();
	}

	// 	/api/search/albumInfo/findRankingList/{category1Id}/{dimension}
	@Operation(summary = "获取排行榜列表")
	@Parameters({
			@Parameter(name = "category1Id", description = "一级分类", in = ParameterIn.PATH, required = true),
			@Parameter(name = "dimension", description = "热度:hotScore、播放量:playStatNum、订阅量:subscribeStatNum、购买量:buyStatNum、评论数:albumCommentStatNum", required = true, in = ParameterIn.PATH),
	})
	@GetMapping("findRankingList/{category1Id}/{dimension}")
	public Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable Long category1Id, @PathVariable String dimension) {
		List<AlbumInfoIndexVo> infoIndexVoList = searchService.findRankingList(category1Id, dimension);
		return Result.ok(infoIndexVoList);
	}


}

